package com.example.demo.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PartitionsTool {
    private static final Logger LOGGER = LoggerFactory.getLogger(PartitionsTool.class);

    private static final int KAFKA_PARTITIONS = 64;//change disable

    /*
   deliver
    */
    public static int getDeliverPartition(long msgId) {
        return leapMsgId(msgId);
    }

    
    private static int leapMsgId(long msgId) {
        return leap(msgId, 1, KAFKA_PARTITIONS);
    }

    /**
     * 分区地检测
     *
     * @param id         id区域
     * @param leap       跳跃跨度的长, 正整数
     * @param partitions 区域数量, 正整数
     * @return 最终落到的区域
     */
    private static int leap(long id, int leap, int partitions) {
        return (int) Math.abs((id / leap) % partitions);
    }
    
}
